import res as res
from pywin.dialogs import status
from requests import Response

from py.generateLicense import LicenseHelper

def test():
    oper = LicenseHelper()
    read_bool, license_dic = oper.read_license(license)
    if not read_bool:
        res['status'] = False
        res['msg'] = "读取失败, 无效的License, 错误信息: {}".format(license_dic)
        return Response(res, status=status.HTTP_422_UNPROCESSABLE_ENTITY)
    date_bool = oper.check_license_date(license_dic['time_str'])
    psw_bool = oper.check_license_psw(license_dic['psw'])
    if psw_bool:
        if date_bool:
            res['status'] = True
            res['time'] = license_dic['time_str']
            res['msg'] = ""
        else:
            res['status'] = False
            res['time'] = license_dic['time_str']
            res['msg'] = "激活码过期"
    else:
        res['status'] = False
        res['time'] = license_dic['time_str']
        res['msg'] = "MAC不匹配, License无效, 请更换License"
    if psw_bool and date_bool:
        serializer_content = {
            "license": license,
            "end_time": license_dic['time_str']
        }
        license_serializer.save(**serializer_content)
        return Response(res, status=status.HTTP_200_OK)
    else:
        return Response(res, status=status.HTTP_422_UNPROCESSABLE_ENTITY)